<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : '{{ urlfor "ProductsattributeController.DataGrid"}}'
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData)
			$('#search_key').val() ? params.Filter = $('#search_key').val() : '';
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"mDataProp" : "Id", "bSortable": false}
			,{"mDataProp" : "OptionName","bSortable": false}
			,{"mDataProp" : "OptionKey","bSortable": false}
			,{"mDataProp" : "Status","bSortable": false, render: function(data, type, full, meta){
				return data == 1 ? '<span class="am-badge am-badge-success">正常</span>' : '<span class="am-badge">禁用</span>';
			}}
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"15%",
				"render": function ( data, type, full, meta ) { 
					btns = '<div class="tpl-table-black-operation">';
					btns += '&nbsp;<a  class="am-btn am-btn-secondary am-btn-xs" onclick="editOptions('+ full.Id +');return false">编辑</a>';
					if(full.Status == 0) {
						btns += '&nbsp;<a href="javascript:;" class="am-btn am-btn-danger am-btn-xs" onclick="delOptions('+ full.Id +');return false;">启用</a></div>';
					} else {
						btns += '&nbsp;<a href="javascript:;" class="am-btn am-btn-default am-btn-xs" onclick="delOptions('+ full.Id +');return false;">禁用</a></div>';
					}
					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : false
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : false //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
	

	function delOptions(id) {
		layer.confirm('确定要操作所选记录吗？！', function(index){
			$.post('{{ urlfor "ProductsattributeController.Delete"}}', {id:id}, function(res){
				if(res.code == 1) {
					layer.msg(res.msg)
				} else {
					tables.ajax.reload();
				}
				layer.close(index);
			}, 'json');
		});
	}
	function dialogReback() {
		tables.ajax.reload();
	}
	
	function editOptions(Id) {
        var title = '添加配置';
        if (Id > 0) {
            title = "编辑配置"
        }
        var url = '{{ urlfor "ProductsattributeController.Edit"}}' + '/' + Id;
        layer.open({
            type: 2,
            title: title,
            shadeClose: false,
            shade: 0.2,
            maxmin: true,
            shift: 1,
            area: ['660px', '580px'],
            content: url
        });
    }
</script>